package com.zhbcm.websocketstudy.controller;

import com.zhbcm.websocketstudy.websocket.WebSocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/3/9 22:59
 */
@Controller
public class TestController
{
    @Autowired
    private WebSocketService webSocketService;

    @GetMapping("/greeting")
    public ModelAndView sayHello(ModelAndView mv)
    {
        mv.setViewName("/greeting");
        mv.addObject("title", "欢迎使用Thymeleaf!");
        return mv;
    }

    @GetMapping("/send")
    @ResponseBody
    public void sendMessage() throws InterruptedException
    {
        webSocketService.onMessage("看到此消息证明成功了");
        Thread.sleep(5000);
        webSocketService.onMessage("第二条消息!");
    }
}
